/*
 * Seq_File Example (linux-5.10)
 * Don't care llseek, only simple read
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>

#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/seq_file.h>
#include <linux/slab.h>

//#define SIMPLE 1

static struct dentry *my_dbgfs_entry;

static int my_entry_show(struct seq_file *seq, void *v)
{
	seq_printf(seq, "Hello World\n");
	return 0;
}

#ifndef SIMPLE
static int my_seqfile_open(struct inode *inode, struct file *file)
{
	return single_open(file, &my_entry_show, NULL);
}

static const struct file_operations my_entry_fops = {
	.open = my_seqfile_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

#else

DEFINE_SHOW_ATTRIBUTE(my_entry);

#endif


static int __init my_seqfile_init(void)
{
	pr_info("%s...\n", __func__);

	my_dbgfs_entry = debugfs_create_file("myseq", 0444, NULL, NULL, &my_entry_fops);
	if (!my_dbgfs_entry) {
		pr_err("debugfs create failed\n");
		return -ENOMEM;
	}

	return 0;
}

static void __exit my_seqfile_exit(void)
{
	pr_info("%s...\n", __func__);

	if (my_dbgfs_entry)
		debugfs_remove(my_dbgfs_entry);
}

module_init(my_seqfile_init);
module_exit(my_seqfile_exit);

MODULE_LICENSE("GPL");
